<%--
  Created by IntelliJ IDEA.
  User: 0xdF
  Date: 2022/11/30
  Time: 9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<jsp:include page="./head.jsp"/>
<head>
    <meta charset="UTF-8">
    <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
    <link rel="stylesheet" href="./css/layui.css">
    <title>邮件发送</title>
</head>
<body>
<form>
    <label class="layui-form-label" style="font-weight: bolder;font-size: 20px">邮箱登录</label>
    <div class="layui-form-item">
        <label class="layui-form-label">
            用户名:
        </label>
        <div class="layui-input-inline">
            <input type="text" name="username" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">
            邮&nbsp;&nbsp;&nbsp;&nbsp;箱:
        </label>
        <div class="layui-input-inline">
            <input type="text" name="email" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
    <label class="layui-form-label">
        验证码:
    </label>
    <div class="layui-input-inline" style="display: flex">
        <input type="text" name="code" width="80%" class="layui-input">
        <input type="button" name="username" width="20%" value="发送" onclick="send()" class="layui-btn layui-btn-primary">
    </div>
    </div>
    <input type="button" name="sub" value="登录" onclick="login()" class="layui-btn layui-btn-danger" style="margin-left: 130px">
</form>
</body>
<script>
    function send(){
        var username = $("input[name='username']").val();
        var email = $("input[name='email']").val();
        if(username.length<=0||email.length<=0||isEmail(email)){
            alert("姓名和邮箱不能为空！");
        }else{
            $.post('sendEmail.do',{
                'username':username,
                'email':email
            },function (res){
                alert(res);
            })
        }
    }
    function login(){
        var username = $("input[name='username']").val();
        var email = $("input[name='email']").val();
        var code =  $("input[name='code']").val();
        $.post('loginByEmail.do',{
            "username":username,
            "email":email,
            "code":code
        },function (res){
            alert(res);
            if(res.charAt(2)==='成'){
                location.href = "index.jsp"
            }
        })
    }
    function isEmail(){
        return false;
    }
</script>
</html>
